package com.demohomework.homeworkdemo.mapper;

import com.demohomework.homeworkdemo.pojo.Assignment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AssignmentMapper {

    //新增作业
    @Insert("insert into assignment(title, description,due_date,course_id,teacher_id,created_at,updated_at)" +
            " values(#{title},#{description},#{dueDate},#{courseId},#{teacherId},now(),now())")
    void add(Assignment assignment);

    //查询所有
    @Select("select * from assignment where teacher_id = #{id}")
    List<Assignment> list(Integer id);

    //根据id查询作业
    @Select("select * from assignment where id = #{id}")
    Assignment findId(Integer id);

    //更新作业
    @Update("update assignment set title = #{title}, description = #{description}," +
            " due_date=#{dueDate},overdue=#{overdue},is_score=#{isScore}, updated_at = now()" +
            " where id = #{id}")
    void update(Assignment assignment);

    //删除作业
    @Update("delete from assignment where id = #{id}")
    void delete(Assignment assignment);

    //根据课程id查询作业
    @Select("select * from assignment where course_id = #{courseId}")
    List<Assignment> listByCourseId(Integer courseId);

    //根据id删除作业
    @Delete("delete from assignment where id = #{id}")
    void deleteById(int id);
}
